package renguanyu.app.auth4fx.view.permission;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import renguanyu.app.auth4fx.App;
import renguanyu.app.auth4fx.controller.permission.PermissionInfoSaveController;

public class PermissionInfoSaveView extends BorderPane {

    public PermissionInfoSaveView(){
        VBox formPane = createFormPane(); // 表单面板
        HBox bottomBar = createOperatePane(); // 操作面板
        super.setBottom(bottomBar); // 组装
        super.setCenter(formPane);
    }

    public StringProperty nameProperty = new SimpleStringProperty();
    public StringProperty passwordProperty = new SimpleStringProperty();
    private VBox createFormPane() {
        Label nameLabel = new Label("权限名：");
        TextField nameField = new TextField();
        HBox nameRow = new HBox(nameLabel, nameField);
        VBox formPane = new VBox(nameRow);

        nameLabel.setAlignment(Pos.CENTER_RIGHT);
        nameLabel.setMinWidth(60);

        nameField.textProperty().bindBidirectional(nameProperty);
        HBox.setHgrow(nameField, Priority.ALWAYS);

        nameRow.setAlignment(Pos.CENTER_LEFT);
        VBox.setMargin(nameRow, new Insets(0, 0, 10, 0));
        formPane.setPadding(new Insets(15, 15, 15, 15));
        return formPane;
    }

    private HBox createOperatePane() {
        Button saveBtn = new Button("新增");
        Button backBtn = new Button("返回");
        HBox bottomBar = new HBox(10, saveBtn, backBtn);

        saveBtn.setOnAction(e-> new PermissionInfoSaveController(this).execute());
        backBtn.setOnAction(e-> App.mainView.setCenter(new PermissionListView()));
        bottomBar.setAlignment(Pos.CENTER);
        bottomBar.setPadding(new Insets(15, 15, 15, 15));
        return bottomBar;
    }

}
